layui.use(['table','form','laydate'], function(){
	var table = layui.table;
	var layer = layui.layer;
	var laydate = layui.laydate;
	var $ = layui.$;
	var form = layui.form;
	laydate.render({
	    elem: '#time'
	  });
	laydate.render({
	    elem: '#time1'
	  });
	laydate.render({
	    elem: '#time2'
	  });
	laydate.render({
	    elem: '#time3'
	  });
	layer.config({
		  skin: 'demo-class'
		})
		//CSS 
		
	//执行渲染
	table.render({
	  elem: '#noticeTable' //指定原始表格元素选择器（推荐id选择器）
	  ,cols: [[
	          {field: 'id',type:'radio', title: '选择'},
	          {field: 'headline', title: '标题',templet: '#headlineTpl'},
	          {field: 'issuer', title: '创建人'},
	          {field: 'releasetime', title: '发布时间' }
	   ]] //设置表头	  
      ,url:'notice/show.html'
     ,page:true
	  ,parseData: function(res){//res 即为原始返回的数据
		    return {
		        "code": 0, //解析接口状态
		        "msg": "", //解析提示文本
		        "count": res.length, //解析数据长度
		        "data": res //解析数据列表
		      };
	  }
	 
	});
	
	active = {
	    add: function(){ //获取选中数据
	    	  layer.open({
	    		  type: 1,
	    		  title: ['添加公告', 'font-size:18px;'],
	    		  skin: 'layui-layer-rim', //加上边框
	    		  offset: '70px',
	    		  area: ['500px', '500px'], //宽高
	    		  move: false,
	    		  content: $('#fm')
	    	});
	    }
	    ,update: function(){ //获取选中数目
	      var checkStatus = table.checkStatus('noticeTable')
	      ,data = checkStatus.data;
	      if(data.length == 0){
	    	  return;
	      }
	      console.info(data[0]);
	      layer.open({
			  type: 1,
			  title: ['修改公告', 'font-size:18px;'],
			  skin: 'layui-layer-rim', //加上边框
			  offset: '70px',
			  area: ['500px', '500px'], //宽高
			  move: false,
			  content: $('#fm_update')
			  
	      });
	      form.val("noticeUpdate",data[0]);
	      form.render('radio');
	    }
	    ,del: function(){ 
	      var checkStatus = table.checkStatus('noticeTable');
	      data = checkStatus.data;
	      if(data.length == 0){
	    	  return;
	      }
		  layer.confirm('确定删除吗？'
				  ,{icon: 3,  area: ['420px', '200px'], //宽高
					  move: false,
					  offset: '90px'}
				  ,function(index){
					$.post("notice/delete.html","id="+data[0].id,function(data){
						table.reload('noticeTable');
						layer.close(index);
					});
				});
		}
	};
		  
	
	$('.rolemanager .layui-btn').on('click', function(){
	    var type = $(this).data('type');
	    active[type] ? active[type].call(this) : '';
	  });
	
});
/*
$("#add").click(function(){

	layui.use('layer', function(){
  var layer = layui.layer;
  layer.msg('hello');
  layer.open({
	  type: 1,
	  title: ['新增角色', 'font-size:18px;'],
	  skin: 'layui-layer-rim', //加上边框
	  offset: '70px',
	  area: ['420px', '280px'], //宽高
	  move: false,
	  content: $('#fm')
});
}); 
});

$("#update").click(function(){
	
	layui.use('layer', function(){
	  var layer = layui.layer;
	  layer.open({
		  type: 1,
		  title: ['修改角色', 'font-size:18px;'],
		  skin: 'layui-layer-rim', //加上边框
		  offset: '70px',
		  area: ['420px', '280px'], //宽高
		  move: false,
		  content: $('#fm_update')
	});
	});
	$(":radio").each(function(){
		if($(this).prop("checked")){
			var cb = $(this).parent().parent().attr("id");
			$.post("role/show.html","id="+cb,function(data){
				for ( var i in data){
				$('#rolecode').val(data[0].rolecode);
				$('#rolename').val(data[0].rolename);
				$('#id').val(data[0].id);
				$("input[name='isstart']").each(function(){
					if($(this).val()==1){
						$(this).prop("checked", true);
					}else{
						$(this).prop("checked", false);
					}
				}) 
				}
			}, "json");
		}
	})
});*/

/*$("#delete").click(function(){
	layui.use('layer', function(){
		  var layer = layui.layer;
		  layer.open({
			  content: '确定删除吗？'
			  ,btn: ['确定', '取消']
			  ,yes: function(index, layero){
			    //按钮【按钮一】的回调
						$(":radio").each(function(){
							if($(this).prop("checked")){
								var cb = $(this).parent().parent().attr("id");
								console.log(cb)
								$.post("role/delete.html","id="+cb,function(data){
									location.reload();
								})
							}
						})
				
			  }
			  ,btn2: function(index, layero){
			    //按钮【按钮二】的回调
			    
			    //return false 开启该代码可禁止点击该按钮关闭
			  }
			  ,cancel: function(){ 
			    //右上角关闭回调
			    
			    //return false 开启该代码可禁止点击该按钮关闭
			  },
			  area: ['420px', '200px'], //宽高
			  move: false,
			  offset: '90px'
			});
});
});*/
	/*$(function() {
		var list ={};
		$.post("role/show.html", "", function(data) {
		 	list = data;
			show(list);
			
		}, "json");

		function show(list) {
			$("#tbody").html("");
			for ( var i in list){
				$("#tbody").append($("<tr id="+list[i].id+">"));
				$("#" + list[i].id)
						.append(
								$("<td>")
										.append(
												$("<input type='radio' name='xuance' id=radio"+list[i].id+" />")));
				$("#" + list[i].id).append($("<td>").html(list[i].rolecode));
				$("#" + list[i].id).append($("<td>").html(list[i].rolename));
				$("#" + list[i].id).append($("<td>").html(list[i].createdby));
				$("#" + list[i].id)
						.append(
								$("<td>")
										.append(
												$("<input type='checkbox' name='xuance' id=box"+list[i].id+" />")));
				var isstart = list[i].isstart;
				if (isstart == 1) {
					$("#box" + list[i].id).prop("checked", true);
				} else {
					$("#box" + list[i].id).prop("checked", false);
				}
				$("#" + list[i].id).append(
						$("<td>").html(list[i].createddate));
			}
		}
		$("#tbody").on(
				"click",
				":checkbox",
				function() {
					var cb = $(this).parent().parent().attr("id");
					console.log(cb)
					var s = null;
					if ($(this).prop("checked")) {
						s = 1;
					} else {
						s = 0;
					}
					$.post("role/shifo.html", "id=" + cb + "&isstart="+ s, function() {

					});
				});
	});*/